Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use configuration flags for //src/conditions:darwin_arm64 #12653

Conversation

thii
Copy link
Member

@thii thii commented Dec 7, 2020

Partially reverts 6d637f4, to allow
cross-compiling Bazel from darwin_x86_64 to darwin_arm64 with
the --cpu=darwin_arm64 flag.

The only source that is different between darwin_x86_64 and darwin_arm64
now is the embedded JDK.

Partially reverts 6d637f4, to allow
cross-compiling Bazel from darwin_x86_64 to darwin_arm64 with
the `--cpu=darwin_arm64` flag.

The only source that is different between darwin_x86_64 and darwin_arm64
now is the embedded JDK.
@google-cla google-cla bot added the cla: yes label Dec 7, 2020
@thii thii marked this pull request as ready for review December 7, 2020 20:10
@thii
Copy link
Member Author

thii commented Dec 7, 2020

@philwo @comius Could you take a look?

"@platforms//os:macos",
"@platforms//cpu:arm64",
],
values = {"cpu": "darwin_arm64"},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of removing the constraint version entirely, use https://github.com/bazelbuild/bazel-skylib/blob/master/docs/selects_doc.md#selectsconfig_setting_group to use either setting.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't whatever you're doing already work by setting both --cpu and --platforms=//:target with platform(name="target", constraint_values=[ "@platforms//os:macos", "@platforms//cpu:arm64"])?

I don't know what state of CC crosscompilation platformization is. But specifying both platform and flags should get you to the same state as before conditions package was modified.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Building with both --cpu=darwin_arm64 and --platforms=//:target gets me this:

INFO: Invocation ID: 7514df6d-c786-4d10-8592-179657b0750b
DEBUG: /private/var/tmp/_bazel_admin/058bf0aeee6f9b65e93a9de41f4a4c2c/external/bazel_toolchains/rules/rbe_repo/checked_in.bzl:103:14: rbe_ubuntu1804_java11 not using checked in configs as detect_java_home was set to True
DEBUG: /private/var/tmp/_bazel_admin/058bf0aeee6f9b65e93a9de41f4a4c2c/external/bazel_toolchains/rules/rbe_repo/checked_in.bzl:103:14: rbe_ubuntu1604_java8 not using checked in configs as detect_java_home was set to True
INFO: Build option --platforms has changed, discarding analysis cache.
ERROR: While resolving toolchains for target //src/main/cpp:client: No matching toolchains found for types @bazel_tools//tools/cpp:toolchain_type. Maybe --incompatible_use_cc_configure_from_rules_cc has been flipped and there is no default C++ toolchain added in the WORKSPACE file? See https://github.com/bazelbuild/bazel/issues/10134 for details and migration instructions.
ERROR: Analysis of target '//src:bazel' failed; build aborted: No matching toolchains found for types @bazel_tools//tools/cpp:toolchain_type. Maybe --incompatible_use_cc_configure_from_rules_cc has been flipped and there is no default C++ toolchain added in the WORKSPACE file? See https://github.com/bazelbuild/bazel/issues/10134 for details and migration instructions.
INFO: Elapsed time: 0.475s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (47 packages loaded, 179 targets configured)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the dummy cc toolchain isn't being picked up. Would you mind filing this as a separate issue so I can investigate? This PR looks fine to me with the recent change

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather see the problem with dummy cc toolchain fixed than a workaroud.
What happens if you set --incompatible_enable_cc_toolchain_resolution?
Please at least open an issue for dummy cc toolchain and add a TODO here, that is
TODO(issue): remove flag based select when the issue is resolved

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm getting the same error even building with --incompatible_enable_cc_toolchain_resolution.

Copy link
Member

@katre katre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks fine to me, but I'll wait for @comius to comment.

"@platforms//os:macos",
"@platforms//cpu:arm64",
],
values = {"cpu": "darwin_arm64"},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the dummy cc toolchain isn't being picked up. Would you mind filing this as a separate issue so I can investigate? This PR looks fine to me with the recent change

@thii
Copy link
Member Author

thii commented Dec 7, 2020

Thanks for the review. I filed it here: #12655.

@comius comius self-assigned this Dec 8, 2020
@bazel-io bazel-io closed this in 52457b1 Dec 8, 2020
@thii thii deleted the use-configuration-flags-for-src-conditions-darwin_arm64 branch December 8, 2020 12:52
meteorcloudy added a commit that referenced this pull request Apr 20, 2021
After this PR, we can use a x86 version of Bazel to build an ARM64 Bazel binary for Apple Silicon by
```
bazel build --cpu=darwin_arm64 //src:bazel
```
The Bazel client, embedded tools and embedded JDK are all native ARM64 binaries.

Changes in this PR:
1. Add OpenJDK definitions for ARM64 macOS
2. Manually created the embedded JDK binaries on an Apple Silicon machine and uploaded them to the bazel mirror site.
3. AutoCpuConverter.java: identify the cpu value correctly
4. cc_toolchain_config.bzl: Explicitly specify the target platform also in the x86 cc toolchain, so that we can also do cross-platform compile from ARM64 to x86.

With the native arm64 Bazel binary, building Bazel itself takes only half of the time compared with the x86 Bazel binary on an Apple DTK machine:
```
$ bazel build --cpu=darwin_arm64 --disk_cache= --repository_cache= //src:bazel
Starting local Bazel server and connecting to it...
...
Target //src:bazel up-to-date:
  bazel-bin/src/bazel
INFO: Elapsed time: 1044.462s, Critical Path: 180.08s
INFO: 2984 processes: 179 internal, 2092 darwin-sandbox, 1 local, 712 worker.
INFO: Build completed successfully, 2984 total actions

cp  ./bazel-bin/src/bazel ~/bin/bazel-arm64

$ bazel-arm64 clean --expunge

$ bazel-arm64 build --disk_cache= --repository_cache= //src:bazel
Starting local Bazel server and connecting to it...
...
Target //src:bazel up-to-date:
  bazel-bin/src/bazel
INFO: Elapsed time: 464.470s, Critical Path: 114.88s
INFO: 2984 processes: 179 internal, 2092 darwin-sandbox, 1 local, 712 worker.
INFO: Build completed successfully, 2984 total actions

```

Closes: #11628

Closes #12900.

PiperOrigin-RevId: 354058336

Revert default cpu value on x86 macOS to "darwin"

Many downstream projects are still depending on the default cpu value
on x86 macOS being "darwin" instead of "darwin_x86_64"

https://buildkite.com/bazel/bazel-auto-sheriff-face-with-cowboy-hat/builds/412

Related: #11628

Closes #12918.

PiperOrigin-RevId: 354279409

Update platform version to 0.0.4

Use configuration flags for //src/conditions:darwin_arm64

Partially reverts 6d637f4, to allow
cross-compiling Bazel from darwin_x86_64 to darwin_arm64 with
the `--cpu=darwin_arm64` flag.

The only source that is different between darwin_x86_64 and darwin_arm64
now is the embedded JDK.

Closes #12653.

PiperOrigin-RevId: 346298051

Make sure Bazel selects correct remote JDK on Apple Silicon
philwo pushed a commit that referenced this pull request Apr 20, 2021
After this PR, we can use a x86 version of Bazel to build an ARM64 Bazel binary for Apple Silicon by
```
bazel build --cpu=darwin_arm64 //src:bazel
```
The Bazel client, embedded tools and embedded JDK are all native ARM64 binaries.

Changes in this PR:
1. Add OpenJDK definitions for ARM64 macOS
2. Manually created the embedded JDK binaries on an Apple Silicon machine and uploaded them to the bazel mirror site.
3. AutoCpuConverter.java: identify the cpu value correctly
4. cc_toolchain_config.bzl: Explicitly specify the target platform also in the x86 cc toolchain, so that we can also do cross-platform compile from ARM64 to x86.

With the native arm64 Bazel binary, building Bazel itself takes only half of the time compared with the x86 Bazel binary on an Apple DTK machine:
```
$ bazel build --cpu=darwin_arm64 --disk_cache= --repository_cache= //src:bazel
Starting local Bazel server and connecting to it...
...
Target //src:bazel up-to-date:
  bazel-bin/src/bazel
INFO: Elapsed time: 1044.462s, Critical Path: 180.08s
INFO: 2984 processes: 179 internal, 2092 darwin-sandbox, 1 local, 712 worker.
INFO: Build completed successfully, 2984 total actions

cp  ./bazel-bin/src/bazel ~/bin/bazel-arm64

$ bazel-arm64 clean --expunge

$ bazel-arm64 build --disk_cache= --repository_cache= //src:bazel
Starting local Bazel server and connecting to it...
...
Target //src:bazel up-to-date:
  bazel-bin/src/bazel
INFO: Elapsed time: 464.470s, Critical Path: 114.88s
INFO: 2984 processes: 179 internal, 2092 darwin-sandbox, 1 local, 712 worker.
INFO: Build completed successfully, 2984 total actions

```

Closes: #11628

Closes #12900.

PiperOrigin-RevId: 354058336

Revert default cpu value on x86 macOS to "darwin"

Many downstream projects are still depending on the default cpu value
on x86 macOS being "darwin" instead of "darwin_x86_64"

https://buildkite.com/bazel/bazel-auto-sheriff-face-with-cowboy-hat/builds/412

Related: #11628

Closes #12918.

PiperOrigin-RevId: 354279409

Update platform version to 0.0.4

Use configuration flags for //src/conditions:darwin_arm64

Partially reverts 6d637f4, to allow
cross-compiling Bazel from darwin_x86_64 to darwin_arm64 with
the `--cpu=darwin_arm64` flag.

The only source that is different between darwin_x86_64 and darwin_arm64
now is the embedded JDK.

Closes #12653.

PiperOrigin-RevId: 346298051

Make sure Bazel selects correct remote JDK on Apple Silicon
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants